package com.yc.store.servlet;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.Gson;
import com.yc.store.bean.Bill;
import com.yc.store.bean.Goods;
import com.yc.store.mapper.BillMapper;
import com.yc.store.mapper.GoodsMapper;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/4/25
 * Email haijunzhou@hnit.edu.cn
 */
@WebServlet("/queryBills")
public class QueryBillServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        WebApplicationContext ioc=
                WebApplicationContextUtils.getWebApplicationContext(req.getServletContext());
        BillMapper billMapper = ioc.getBean(BillMapper.class);
        List<Bill> bills = billMapper.selectAll();
        resp.setContentType("application/json;charset=utf-8");
        Gson gson = new Gson();
        String json = gson.toJson(bills);
        resp.getWriter().append(json);
    }
}
